<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>投票页面</title>
    <#include "/common/link.ftl">

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <#assign currentMenu="activity"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>投票页面</h1>
        </section>
        <section class="content">
            <div class="box" style="padding: 10px">
                <div class="row">

                    <div class="col-md-offset-4 col-md-8">
                        <h1>${activity.title}</h1>
                    </div>
                    <div class="col-md-12">
                        <div class="panel panel-default container">
                            <div class="panel-body">
                                <form id="editForm" action="/xxxxx" method="post">
                                    <input type="hidden" name="activityId" value="${activityId}">
                                    <#list items as item>
                                    <div class="row">
                                        <div class="col-md-2">
                                            <div class="radio">
                                                <label>
                                                    <input type="checkbox" name="optionsRadios" class="item" value="${item.id}">
                                                    ${item_index+1}.${item.content}
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                    </#list>
                                    <button type="button" class="btn btn-primary btn-submit">提交</button>
                                </form>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>
<script>
    $('.btn-submit').click(function () {
        let id = -1;
        let activityId = $('input[name=activityId]').val();
        //遍历集合,看哪个被选中了
        $('.item').each(function (i,ele) {
            let check = $(ele).prop('checked');
            if (check){
                id = $(ele).val();
            }
        });
        $.post('/activityItem/saveOrUpdate',{"id":id,"activityId":activityId},function (data) {
            if (data.success){
                Swal.fire({
                    title: '投票成功',
                    icon: 'success',
                    confirmButtonText: 'OK',
                }).then((result) => {
                    if (result.value) {
                        //点击确认按钮后做的事情
                        window.location.href="/activityItem/listResult?activityId=" +activityId;
                    }
                })
            }
        })
    })
</script>
</body>
</html>
